package com.gitee.springioc.controller;

import com.gitee.springioc.entity.Order;
import com.gitee.springioc.service.CodeRegist;
import com.gitee.springioc.service.OrderService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ming.yan-1
 * @version V1.0
 * @Title com.gitee.springioc.controller
 * @Description
 * @date 2018/9/14  下午12:56
 */
@RequestMapping(value = "/order")
@RestController
public class OrderController implements BeanFactoryAware {

    private static final Log logger = LogFactory.getLog(OrderController.class);

    private BeanFactory beanFactory;

    @Resource(name = "OrderServiceImpl")
    private OrderService orderServiceCache;
    @Resource(name = "CodeRegist")
    private CodeRegist codeRegist;

    @GetMapping(value = "/cache")
    public String cache(){
        ConcurrentHashMap<String, Order> hashMap = orderServiceCache.getCache();
        logger.info("看下值"+hashMap.entrySet());
        //这个时候才真的进行了实例化、初始化等操作
        this.beanFactory.getBean("PayServiceSelf");
        return hashMap.toString();
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }
}
